<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script !src="">
    "use strict";
    //定义方式1
    let abs = function (x) {
        //可以自定义异常进行抛出 ，typeof 检查类型是否相同
        /*if(typeof x !== "number"){
            throw "Not a Number";
        }*/

        //arguments 代表传入的所有参数，是一个数组
        for (let i = 0; i < arguments.length; i++) {
            console.log(arguments[i]);
        }
        return x >= 0? x:-x;
    };
    console.log(abs("123"));
    console.log(abs(-1));
    console.log(abs(2));

    //定义方式2
    function abs2(x,...rest) {
        console.log(rest);
        return x >= 0? x:-x;
    }

</script>
</body>
</html>